/*
 * jquery.juice.nospam.js
 *
 * Juice Library No Spam v0.1.2
 * Date: 2009-10-07
 * Requires: jQuery v1.3 or later
 * Dual licensed under the MIT and GPL licenses:
 *   http://www.opensource.org/licenses/mit-license.php
 *   http://www.gnu.org/licenses/gpl.html
 *
 * Copyright 2009 Steve Whiteley (http://jui.ce.it)
 */

(function($) {
	$.fn.nospam = function(callerSettings) {
		var settings = $.extend(true, {}, $.fn.nospam.settings, callerSettings);
		return this.each(function() {
			var n = $(this), r = new RegExp(settings.expr, 'gi');
			n.text(n.text().replace(r, settings.replace));
			if (!n.is('a') && settings.link) {
				n.wrapInner('<a />')
					.children(':first')
					.attr('href', 'mailto:' + n.text());
			} else if (n.is('a')) {
				n.attr('href', n.attr('href').replace(r, settings.replace));
			}
		});
	};
	$.fn.nospam.settings = {
		expr: '\\b(.*)\\[[^\\\]]+\\](.*)\\b',
		replace: '$1@$2',
		link: true
	};
})(jQuery);